package com.hsylient.demo02;

import lombok.SneakyThrows;

import java.sql.Connection;
import java.sql.Driver;
import java.sql.DriverManager;
import java.sql.Statement;

public class TestInsert {

    private static final String URL = "jdbc:mysql://localhost:3306/test?useSSL=true";
    private static final String USERNAME = "root";
    private static final String PASSWORD = "root";

    @SuppressWarnings("all")
    @SneakyThrows
    public static void main(String[] args) {
        Driver driver = new com.mysql.cj.jdbc.Driver();
        // 注册驱动
        DriverManager.registerDriver(driver);
        // 获取连接
        Connection connection = DriverManager.getConnection(URL, USERNAME, PASSWORD);
        // 获取数据库操作对象
        Statement statement = connection.createStatement();
        // 准备sql
        String sql = "insert into user(id, `username`, password) VALUES (4007, '心xxxxxx态崩了dd', 'caoxxcao')";
        // 执行sql
        int executeResult = statement.executeUpdate(sql);
        // 打印结果
        String result = executeResult == 1 ? "插入成功" : "插入失败";
        System.out.println(result);
        // 关闭资源
        statement.close();
        connection.close();
    }
}
